//
//  ISTabBarController.m
//  iSocket
//
//  Created by lhj on 1/21/16.
//  Copyright © 2016 boer. All rights reserved.
//

#import "IMTabBarController.h"
#import <UINavigationController+FDFullscreenPopGesture.h>
#import "IMMainController.h"
#import "IMMallController.h"
#import "IMDiscoverController.h"
#import "IMMineController.h"

@interface IMTabBarController ()

@end

@implementation IMTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setupTabBar];
    
    [self setupAllChildVces];
    
    self.fd_prefersNavigationBarHidden = YES;
}

- (void)setupTabBar
{
    UITabBarItem *item = [UITabBarItem appearance];
    
    NSMutableDictionary *normalAttrs = [NSMutableDictionary dictionary];
    normalAttrs[NSFontAttributeName] = [UIFont systemFontOfSize:10];
    normalAttrs[NSForegroundColorAttributeName] = [UIColor colorFromHexRGB:@"75809c"];
    [item setTitleTextAttributes:normalAttrs forState:UIControlStateNormal];
    
    NSMutableDictionary *selectedAttrs = [NSMutableDictionary dictionary];
    selectedAttrs[NSForegroundColorAttributeName] = IMCOLOR;
    [item setTitleTextAttributes:selectedAttrs forState:UIControlStateSelected];
    
    self.tabBar.shadowImage = [UIImage imageWithColor:IMColorAlpha(117, 128, 156, 0.75)];
    self.tabBar.backgroundImage = [UIImage imageWithColor:[UIColor colorFromHexRGB:@"efeff4"]];
}

- (void)setupAllChildVces
{
    IMMainController *main = [[IMMainController alloc] init];
    [self setupChildVc:main title:@"首页" image:@"定时_nor" selectedImage:@"定时_press"];
    
    IMMallController *mall = [[IMMallController alloc] init];
    [self setupChildVc:mall title:@"商城" image:@"定时_nor" selectedImage:@"定时_press"];
    
    IMDiscoverController *dis = [[IMDiscoverController alloc] init];
    [self setupChildVc:dis title:@"发现" image:@"定时_nor" selectedImage:@"定时_press"];
    
    IMMineController *mine = [[IMMineController alloc] init];
    [self setupChildVc:mine title:@"我的" image:@"定时_nor" selectedImage:@"定时_press"];
    
}

- (void)setupChildVc:(IMBaseController *)vc title:(NSString *)title image:(NSString *)image selectedImage:(NSString *)selectedImage
{
    
    // 添加子控制器
    IMBaseNavigationController *nav = [[IMBaseNavigationController alloc] initWithRootViewController:vc];
    [self addChildViewController:nav];
    
    vc.title = title;
//    vc.tabBarItem.image = [UIImage imageNamed:image];
//    vc.tabBarItem.selectedImage = [UIImage imageNamed:selectedImage];
    
    nav.tabBarItem.titlePositionAdjustment = UIOffsetMake(0, -3);
}

@end
